package team.szm.scd.common;

import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

public class VerifyCodeUtils {
    public static String getVerifyCode(MockMvc mockMvc, MockHttpSession session) throws Exception {
        MockHttpServletRequestBuilder requestBuilder =
                MockMvcRequestBuilders.get("/verify_code")
                        .accept(MediaType.APPLICATION_JSON)
                        .session(session);
        mockMvc.perform(requestBuilder).andExpect(MockMvcResultMatchers.status().isOk())//断言状态码是200
                .andReturn();
        return (String) session.getAttribute("verify_code");
    }
}
